package com.study.d012Components;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * ColorPicker颜色选择器的使用
 * @author Administrator
 *
 */
public class ColorPickerMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		stage.show();

		AnchorPane aPane = new AnchorPane();
		ColorPicker cp  =new ColorPicker();

		/**
 		 * 使用setOnAction() 和valueProperty() 都可以进行监听
 		 */
		cp.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				System.out.println("当前选中的颜色是:" + cp.getValue().toString());

			}
		});

		cp.valueProperty().addListener(new ChangeListener<Color>() {
			@Override
			public void changed(ObservableValue<? extends Color> observable, Color oldValue, Color newValue) {
				System.out.println(newValue.toString());
			}
		});



		stage.setScene(new Scene(aPane,400,300));

		aPane.getChildren().add(cp);
		AnchorPane.setTopAnchor(cp, 30.0);
		AnchorPane.setLeftAnchor(cp, 30.0);


	}
}
